package com.choudou5.nlp.util;

import com.choudou5.nlp.config.AppKeyBean;
import com.choudou5.solr.util.http.HttpUtils;
import com.qcloud.Module.Wenzhi;
import com.qcloud.QcloudApiModuleCenter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.TreeMap;

/**
 * @name
 * @author choudou5
 * @date 2018-08-07
 */
public class QCloudUtil {

    private static final Logger logger = LoggerFactory.getLogger(QCloudUtil.class);

    private static final Random rd = new Random();



    public static void main(String[] args) {
        String secretId = "AKID7Kj4eAWwb4NUQE4T1Sp11qTwGPUDHeAU";
        String secretKey = "JDza3e9WiiW8YnrjThjcJo6C6pMp6GI9";

//        1251570887
        AppKeyBean appKey = null;
        String url = getTextAnalysis(appKey, "波尔多红酒怎么样");
        HttpUtils.get(url);
    }


    //https://cloud.tencent.com/document/api/271/2071

    public static String getTextAnalysis(AppKeyBean appKey, String text){
        String action = "LexicalAnalysis";
        TreeMap<String, Object> config = new TreeMap();
        config.put("SecretId", appKey.getSecretId());
        config.put("SecretKey", appKey.getSecretKey());
        config.put("RequestMethod", "GET");
        config.put("DefaultRegion", "gz");
        QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Wenzhi(), config);
        TreeMap<String, Object> params = new TreeMap();
        params.put("text", text);
        params.put("code", "2097152");
        System.out.println(module.generateUrl(action, params));
        String result = null;
        try {
            result = module.call(action, params);
            appKey.useOne(); //使用一次
        } catch (Exception e) {
            logger.error("文本分析失败", e);
        }
        return result;
    }


}
